home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / task3210.zip / TEST.C < prev   
Text File  |  1996-10-26  |  2KB  |  84 lines

  1. // ***** TEST.C *****
  2. // For testing the Tasker32 routines.
  3. // If you have the shareware version compile with -DSHAREWARE
  4.  
  5. //Load includes
  6. #include "task32.h"                 //Load this first!!
  7. #include <stdio.h>
  8. #include <conio.h>
  9. #include <time.h>
  10. #include <stdlib.h>
  11.  
  12. //Global variables
  13. ulong     count[TASK_NUM]={0,0,0,0,0,0,0,0,0,0};  //Some counts
  14. ushort    tid[TASK_NUM+1];                        //Task ID's
  15. ushort    SS;                                     //Stack seg
  16. ulong     ESP;                                    //Stack ptr
  17. ushort    scrtop;                                 //Line for top of display
  18.  
  19. //Func prototypes
  20. void Hnd(ushort);                   //Handler declaration
  21.  
  22. void main()
  23. {
  24.   //Some variables:
  25.   time_t  *curtime;                 //Gets the time
  26.   int     k;                        //from getch() and a counter
  27.   ushort  next=0;                   //Next task to add
  28.  
  29.   //Initilize the tasker and check for error
  30.   clrscr();
  31.   if( task_init_tasker() != TASK_OK ) {
  32.     puts("ERROR: Failed to init tasker");
  33.     return;
  34.   }
  35.   atexit((void (*)())task_end_tasker);
  36.  
  37.   //Initialize screen garbage
  38.   printf("[A]dd Task  [D]elete Task  [P]ause  [U]npause\n");
  39.   scrtop=wherey();
  40.   for(k=0;k<TASK_NUM;k++)
  41.     printf(" Task %1d\n",k);
  42.  
  43.   //Run the tasker
  44.   while( (k=getch())!=27 ) {
  45.     if(k=='a' || k=='A') {
  46.       tid[next]=task_add(random(50)+18,Hnd,_CS,_DS,0);
  47.       #ifndef SHAREWARE
  48.         if(tid[next]!=TASK_NONE_FREE) {
  49.           gotoxy(30,tid[next]+scrtop);
  50.           printf("%2uHz",tasks[tid[next++]].freq);
  51.         }
  52.       #else
  53.         next++;
  54.       #endif
  55.     } else if(k=='d' || k=='D') {
  56.       if(next>0) task_delete(tid[--next]);
  57.     } else if(k=='p' || k=='P') {
  58.       task_setstatus(tid[next-1],TASK_PAUSED);
  59.     } else if(k=='u' || k=='U') {
  60.       task_clearstatus(tid[next-1],TASK_PAUSED);
  61.     }
  62.   }
  63.   task_end_tasker();
  64.  
  65.   //Display some stuff
  66.   gotoxy(1,10+scrtop);
  67.   printf("Ended...... SS=%04X _SS=%04X  ESP=%08lX  _ESP=%08X",
  68.               SS,_SS,ESP,_ESP);
  69.   #ifndef SHAREWARE
  70.     for(k=0;k<TASK_NUM;k++) {
  71.       printf("\ntid=%d  count=%8u  status=%5hu  delay=%6u  freq=%6u",
  72.         k,count[k],tasks[k].status,tasks[k].delay,tasks[k].freq);
  73.     }
  74.   #endif
  75. }
  76.  
  77. void Hnd(const ushort tid)            //Main handler
  78. {
  79.   SS=_SS; ESP=_ESP;
  80.   gotoxy(10,tid+scrtop); 
  81.   printf("%u",++count[tid]);
  82. }
  83.  
  84.